package com.example.demo.day0301;

import java.io.BufferedReader;
import java.io.FileReader;

public class DemoBufferedReader {
    public static void main(String[] args) {
        try {
            DemoBufferedReader.testBufferedReader();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void testBufferedReader() throws Exception {
        FileReader fr = new FileReader("D:\\demo\\src\\main\\java\\com\\example\\demo\\day0301\\tt.txt");//字符输入流

        BufferedReader bre = new BufferedReader(fr);//缓冲字符输入流

        char[] c = new char[100];//缓冲数组
        int len = 0;

        while((len = bre.read(c)) != -1 ){//直到br.read执行到没有字符串，此时返回值为-1。不再读取文件
            System.out.println(new String(c,0,len));
        }
        bre.close();
        fr.close();//关闭流，先开后关
    }
}
